<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>生成数组</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f4f7fc;
        }
        .container {
            max-width: 800px;
            margin: 30px auto;
            background-color: #fff;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }
        h1 {
            text-align: center;
            color: #333;
            font-size: 24px;
        }
        form {
            margin-bottom: 20px;
        }
        label {
            font-size: 16px;
            margin-right: 10px;
            color: #333;
        }
        input[type="number"], select {
            padding: 8px;
            font-size: 16px;
            border: 1px solid #ccc;
            border-radius: 5px;
            margin-bottom: 10px;
            width: 100%;
            max-width: 200px;
        }
        button {
            background-color: #4CAF50;
            color: white;
            padding: 10px 20px;
            font-size: 16px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            width: 100%;
            max-width: 200px;
            margin-top: 10px;
        }
        button:hover {
            background-color: #45a049;
        }
        .array-display {
            margin-top: 20px;
            font-size: 16px;
            color: #333;
            background-color: #f7f7f7;
            padding: 15px;
            border-radius: 5px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            overflow-x: auto;
        }
        .array-display span {
            display: inline-block;
            width: 60px;
            padding: 5px;
            text-align: center;
            margin-right: 5px;
            margin-bottom: 5px;
            background-color: #e4e4e4;
            border-radius: 5px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        .array-display span:nth-child(10n) {
            margin-right: 0;
        }
        .result {
            margin-top: 20px;
            font-size: 18px;
            color: #333;
            padding: 10px;
            background-color: #e9f7e9;
            border: 1px solid #d1e7d1;
            border-radius: 5px;
        }
        .error {
            color: red;
            font-size: 16px;
            margin-top: 20px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>生成一个数组</h1>

        <form method="post">
            {% csrf_token %}
            <div>
                <label for="n">请输入数组长度 (n)：</label>
                <input type="number" id="n" name="n" required min="1">
            </div>

            <div>
                <label for="method">选择生成方式：</label>
                <select id="method" name="method">
                    <option value="random" selected>随机选择</option>
                    <option value="0">未排序</option>
                    <option value="1">升序</option>
                    <option value="2">降序</option>
                    <option value="3">先升后降</option>
                    <option value="4">先降后升</option>
                </select>
            </div>

            <button type="submit">生成数组</button>
        </form>

        {% if arr %}
            <h2>生成的数组：</h2>
            <div class="result">
                <p>数组长度：{{ n }}，生成方式：{{ method }}</p>
            </div>

            <div class="array-display">
                {% for num in arr %}
                    <td>{{ num }}</td>
                {% endfor %}
            </div>
        {% endif %}
        <button><a href="{% url 'experiment2' %}" style="text-decoration: none; color: white">返回上一页</a></button>
    </div>
</body>
</html>
